<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="学届" prop="yearType">
                <el-select v-model="queryParams.yearType" placeholder="请选择学届" clearable>
                    <el-option v-for="dict in dict.type.stu_year_list" :key="dict.value" :label="dict.label" :value="dict.value"/>
                </el-select>
            </el-form-item>
            <el-form-item label="课程名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入课程名称" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="老师姓名" prop="teacher">
                <el-input v-model="queryParams.teacher" placeholder="请输入老师姓名" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <TableCard>
            <el-table  :border="Global.tableShowBorder" v-loading="loading" :data="lessonList" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" align="center"/>
                <el-table-column label="学届" align="center" width="80" prop="yearType">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.stu_year_list" :value="scope.row.yearType"/>
                    </template>
                </el-table-column>
                <el-table-column label="课程名称" align="center" prop="name"/>
                <el-table-column label="老师姓名" align="center" prop="teacherName"/>
                <el-table-column label="成绩权重" align="center" prop="scoreScale"/>
                <el-table-column label="作业权重" align="center" prop="jobScale"/>
                <el-table-column label="实验权重" align="center" prop="expScale"/>
    <!--            <el-table-column label="备注" align="center" prop="remark"/>-->
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text" icon="el-icon-edit" @click="calc(scope.row)" v-hasPermi="['stu:lesson:edit']">课程达成度计算</el-button>

                        <el-button size="mini" type="text" icon="el-icon-edit" @click="viewChart(scope.row)" v-hasPermi="['stu:lesson:edit']">查看图表</el-button>

                        <el-button size="mini" type="text" icon="el-icon-edit" @click="viewRatio(scope.row)" v-hasPermi="['stu:lesson:edit']">查看成绩比例</el-button>

                    </template>
                </el-table-column>
            </el-table>

            <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
        </TableCard>

        <el-dialog title="查看图表" :visible.sync="showChart" width="1200px">
            <PointTargetChart  ref="ptChart"></PointTargetChart>
        </el-dialog>

        <el-dialog title="查看学生占比" :visible.sync="showViewRatio" width="1200px">
            <StudentRatio ref="studtRadio"></StudentRatio>
        </el-dialog>

    </div>
</template>

<script>
import {listLesson, getLesson, delLesson, addLesson, updateLesson} from "@/api/stu/lesson";
import {listUser} from "@/api/system/user";
import {getToken} from "@/utils/auth";
import PointTargetChart from "@/views/stu/calc/pointTargetChart";
import StudentRatio from "@/views/stu/calc/studentRatio";
import {calcLessonPointTarget, calcStudentRadio} from "@/api/stu/score";
export default {
    name: "Lesson",
    dicts: ['stu_year_list'],
    components: {PointTargetChart,StudentRatio},
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 课程表格数据
            lessonList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                name: null,
                teacher: null,
                teacherId: null,
                inspectPointId: null,
                inspectPointName: null,
                scoreScale: null,
                jobScale: null,
                expScale: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {},
            userList:[],
            upload: {
                // 是否显示弹出层（用户导入）
                open: false,
                // 弹出层标题（用户导入）
                title: "",
                // 是否禁用上传
                isUploading: false,
                lessonId:null,
                // 设置上传的请求头部
                headers: { Authorization: "Bearer " + getToken() },
                // 上传的地址
                url: process.env.VUE_APP_BASE_API + "/stu/score/importData"
            },
            showChart:false,
            showViewRatio:false,
            //图表数据
            chartDataList:[],
            //学生占比
            scoreList:[],
            radioList:[]
        };
    },
    created() {
        this.getList();
        this.getUserList();
    },
    methods: {
        /** 查询课程列表 */
        getList() {
            this.loading = true;
            listLesson(this.queryParams).then(response => {
                this.lessonList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        getUserList(){
            listUser().then((res)=>{
                if(res){
                    this.userList = res.rows;
                }
            })
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                name: null,
                teacher: null,
                teacherId: null,
                inspectPointId: null,
                inspectPointName: null,
                scoreScale: null,
                jobScale: null,
                expScale: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                remark: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        //学生成绩
        calc(row){
            this.$router.push({path:"/stu/calc/viewLessonPointTarget/" + row.id });
        },
        //查看图表
        viewChart(row){
            this.showChart = true;
            calcLessonPointTarget(row.id).then(res => {
                if(res.code==200){
                    let list = [];
                    let data = res.data;
                    let row0 = ['product', '考试达成度', '作业达成度', '实验达成度','总评总分达成度'];
                    list.push(row0);
                    let dataList = data.listData;
                    dataList.forEach((item,index)=>{
                        let row = [];
                        row.push(item.pointName);
                        row.push(item.scoreTarget);
                        row.push(item.jobTarget);
                        row.push(item.expTarget);
                        row.push(item.lessonTarget);
                        list.push(row);
                        console.log(list)
                    })

                    this.chartDataList = list;
                    this.$refs.ptChart.initChart(list);

                    console.log(2222222222)
                    console.log(list)
                }
            });
        },
        //学生占比
        viewRatio(row){
            this.showViewRatio = true;
            calcStudentRadio(row.id).then((res)=>{
                if(res.code==200){
                    console.log(res.data.topTable)
                    this.$refs.studtRadio.setListData(res.data.topTable,res.data.radioTable);
                }
            })

        }

    }
};
</script>
